1
/****************************** Module Header ******************************\
2 Module Name: CSSimpleObject.cs
3 Project: CSClassLibrary
4 Copyright (c) Microsoft Corporation.
6 The code sample demonstrates a C# class library that we can use in other
7 applications. The class library exposes a simple class named CSSimpleObject.
8 The process of creating the class library is very straight-forward.
10 This source is subject to the Microsoft Public License.
11 See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
12 All other rights reserved.
14 THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
15 EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
17 \***************************************************************************/
19 #region Using directives
21 using System
.Diagnostics
;
25 namespace CSClassLibrary
27 public class CSSimpleObject
32 public CSSimpleObject()
36 private float fField
= 0F
;
39 /// This is a public Property. It allows you to get and set the value
42 public float FloatProperty
44 get { return fField; }
47 // Fire the event FloatPropertyChanging
49 if (FloatPropertyChanging
!= null)
51 FloatPropertyChanging(value, out cancel
);
54 // If the change is not canceled, make the change.
63 /// Returns a String that represents the current Object. Here, we
64 /// return the string form of the float field fField.
66 /// <returns>the string form of the float field fField.</returns>
67 public override string ToString()
69 return this.fField
.ToString("F2");
73 /// This is a public static method. It returns the number of
74 /// characters in a string.
76 /// <param name="str">a string</param>
77 /// <returns>the number of characters in the string</returns>
78 public static int GetStringLength(string str
)
84 /// This is an event. The event is fired when the float property is
87 public event PropertyChangingEventHandler FloatPropertyChanging
;
92 /// Property value changing event handler
94 /// <param name="NewValue">the new value of the property</param>
95 /// <param name="Cancel">
96 /// Output whether the change should be cancelled or not.
98 public delegate void PropertyChangingEventHandler(object NewValue
, out bool Cancel
);